﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace a21_RoutedEvent
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly StringBuilder logBuf = new StringBuilder();

        public MainWindow()
        {
            InitializeComponent();
        }

        private void MyClickHandlerInSP(object sender, RoutedEventArgs args)
        {
            logBuf.Clear();

            var fe = (FrameworkElement)sender;
            logBuf.Append("Event handled by element named ");
            logBuf.Append(fe.Name);
            logBuf.Append("\n");
            var fe2 = (FrameworkElement)args.Source;
            logBuf.Append("Event originated from source element of type ");
            logBuf.Append(args.Source.GetType());
            logBuf.Append(" with Name ");
            logBuf.Append(fe2.Name);
            logBuf.Append("\n");
            logBuf.Append("Event used routing strategy ");
            logBuf.Append(args.RoutedEvent.RoutingStrategy);
            logBuf.Append("\n");
            log.Text += logBuf.ToString();
        }

        private void MyClickHandler(object sender, RoutedEventArgs args)
        {
            logBuf.Clear();

            var fe = (FrameworkElement)sender;
            logBuf.Append("Event handled by element named ");
            logBuf.Append(fe.Name);
            logBuf.Append("\n");
            var fe2 = (FrameworkElement)args.Source;
            logBuf.Append("Event originated from source element of type ");
            logBuf.Append(args.Source.GetType());
            logBuf.Append(" with Name ");
            logBuf.Append(fe2.Name);
            logBuf.Append("\n");
            logBuf.Append("Event used routing strategy ");
            logBuf.Append(args.RoutedEvent.RoutingStrategy);
            logBuf.Append("\n");
            log.Text = logBuf.ToString();

            //此句标记event处理完毕, 不再bubble等继续传播
            //args.Handled = true;
        }
    }
}
